<template>
  <div class="components-container">
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :height="height" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

    <goodstypeMaintainashMain ref="dialog" :orderType="order" @refreshData="getData"></goodstypeMaintainashMain>
    <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btnCenter {
  text-align: center;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import goodstypeMaintainashMain from "./goodstypeMaintainashMain";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import staEndUse from "../basic/staEndUse";
import { ORDER } from "@/const/orderConst.js";
import { manage } from "@/mixins/managePage.js";
import DataTableVue from '../../components/Table/DataTable.vue';


const ADD = "新增";
const MODIFYPROJECT = "修改";
const DELETE = "删除";
const INFO = "详情";
const enable = "启用";
const disable = "禁用";

export default {
  name: "chargeProjectManage",
  mixins: [manage],
  data() {
    return {
      height:'700',
      title: null,
      loading: false,
      chargeProjectTypes: [],
      chaStatusTypes: [],
      chaReductionTypes: [],
      chaUintsTypes: [],

      selectData: {},
      chaData: {},

      //价格历史
      dataListLSJG: [],
      headListLSJG: [],
      //分页和排序
      pageOrderLSJG: {
        orderType: null,
        orderSort: null,
        totalNum: null,
        pageSize: 10,
        currentPage: 1
      },
      sweetModalWidth: 80,
      sweetModalMaxWidth: 840,
      hiddenColumn: false
    };
  },
  methods: {
    //收费项目查询
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Depot.QueryAshDpg,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取表头
    getheaderlist(){
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetGoodstypeColumns,
        res => {
          console.log(res);
          this.headList = res.data.content;
        }
      )
    },
    //收费项目历史价格查询
    getPriceHistory() {
      let data = {
        PageIndex: this.pageOrderLSJG.currentPage,
        PageSize: this.pageOrderLSJG.pageSize,
        OrderBy: this.pageOrderLSJG.orderType,
        OrderByType: this.pageOrderLSJG.orderSort,
        Data: { CpechaidEqual: this.currentRow.CHAID }
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().ChargeProject.QueryPriceHistory,
        res => {
          this.dataListLSJG = res.data.content.OutData;
          this.pageOrderLSJG.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //分页和排序
    pageChange(value) {
      this.pageOrder = value;
      this.getData();
    },
    operate(order, id) {
        this.order = order;
        switch (this.order) {
        case ADD:
            this.$refs.dialog.open(this.order);
            break;
        case MODIFYPROJECT:
            this.$refs.dialog.open(this.order,this.currentRow.DPGID);
            break;
        case DELETE:
            this.DpgDelete(this.currentRow.DPGID);
            break;
        case INFO:
            this.$refs.dialog.open(this.order,this.currentRow.DPGID);
            break;
        case enable:
            this.$refs.useMain.open('取消禁用', this.currentRow.DPGID);
            break;
        case disable:
            this.$refs.useMain.open(this.order, this.currentRow.DPGID);
            break;
        default:
        }
    },
    //删除
    DpgDelete(id){
        this.$confirm("确认是否删除该数据?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
              let data = {
                DPGID: id
              };
              apiBase.DoService(
                data,
                apiBase.getApiAdress().Depot.DeleteAshDpg,
                res => {
                  this.getData();
                }
              );
            })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
    btnShow(btn) {
      let status = '';
      if(this.currentRow){
        status = this.currentRow.DPGSTATUS;
      }
      switch (btn) {
        case ADD:
          return true;
          break;
        case MODIFYPROJECT:
        case DELETE:
        case INFO:
          if(this.currentRow) return true;
          break;
        case enable:
          return status === "B";
          break;
        case disable:
          return status === 'A';
          break;
        default:
      }
    },
    //数据重置
    dataRepeat() {
      this.chaData = {};
    },
  },
  components: {
    sweetModal,
    dataTable,
    goodstypeMaintainashMain,
    staEndUse
  },
  mounted() {},
  created() {
    this.getData();
    this.getheaderlist();
  }
};
</script>
